﻿using System;

namespace PusherClient.Example
{
    class Program
    {
        static void Main(string[] args)
        {
            string appKey = args.Length > 0 ? args[0] : "abc243231a132b21c321";
            string channelName = args.Length > 1 ? args[1] : "my-channel";
            string eventName = args.Length > 2 ? args[2] : "my-event";

            Console.WriteLine("Example usage: PusherClient.Example.exe abc243231a132b21c321 my-channel my-event");
            Console.WriteLine("Subscribing to app key '{0}', channel '{1}', event '{2}'", appKey, channelName, eventName);

            IPusher pusher = new Pusher(appKey);
            IChannel channel = pusher.Subscribe(channelName);
            pusher.Connection.Connected += delegate { Console.WriteLine("Connection opened"); };
            pusher.Connection.Disconnected += delegate { Console.WriteLine("Connection closed"); };
            pusher.Connection.Error += channel_Error;

            channel.Bind(eventName, (data) => Console.WriteLine(
                "An event was triggered with message: " + data.Message));

            Console.WriteLine("Press any key to exit");
            Console.ReadLine();

        }

        static void channel_Error(object sender, SuperSocket.ClientEngine.ErrorEventArgs e)
        {
            Console.WriteLine("An error occured: " + e.Exception.Message);
        }
    }
}
